package se.webbzon.boltzmann.game.object.portal;

import se.webbzon.boltzmann.environment.AbstractEnvironment;
import se.webbzon.boltzmann.game.object.player.AbstractPlayerCharacter;
import se.webbzon.boltzmann.resource.Resources;
import se.webbzon.oschi01.worldeditor.DeflatableWorldObject;
import se.webbzon.oschi01.worldeditor.WorldObjectDeflation;
import se.webbzon.oschi01.worldobject.appearance.Appearance3D;
import se.webbzon.oschi01.worldobject.appearance.CubeAppearance3D;
import se.webbzon.oschi01.worldobject.appearance.NoAppearance3D;
import se.webbzon.oschi01.worldobject.appearance.SimpleAppearance3D;

public class SimplePortal extends AbstractPortal implements DeflatableWorldObject {
	
	public static final String worldObjectName = "simplePortal";
	
	/*============================================================
	Constructors
	============================================================*/

	public SimplePortal(AbstractEnvironment env, String worldAreaName, byte portalId) {
		super(0, createAppearance(env), env, worldAreaName, portalId);
	}
	
	/*============================================================
	Public Methods
	============================================================*/

	@Override public void spawn(AbstractPlayerCharacter player) {
		player.setPosition(getX(),getY() + player.getHeight()/2, getZ());
		player.setFacing(getAngle() + Math.PI);
	}

	@Override public String getName() {
		return worldObjectName;
	}

	@Override public WorldObjectDeflation getDeflation() {
		return new SimplePortalDeflation(0,this);
	}
	
	/*============================================================
	Private Methods
	============================================================*/
	
	/** Creates the portal appearance. **/
	private static final Appearance3D createAppearance(AbstractEnvironment env) {
		if (env.isDebugMode()) {
			SimpleAppearance3D appearance = new CubeAppearance3D();
			appearance.setTextureSet(Resources.getTextureSet("misc_unknown"));
			return appearance;
		} else
			return new NoAppearance3D();
	}

}
